package edu.cuit.zhuyimeng.uaa.controller;

import edu.cuit.zhuyimeng.framework.common.result.CommonResult;
import edu.cuit.zhuyimeng.uaa.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理接口
 */
@Tag(name = "用户管理接口")
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserManageController {

    private final IUserService userService;

    /**
     * 删除用户
     *
     * @param name 用户名
     */
    @DeleteMapping("/")
    @Operation(summary = "删除用户", security = @SecurityRequirement(name = "Authorization"))
    public CommonResult<Void> deleteUser(@RequestParam("name") @NotBlank String name) {
        userService.deleteUser(name);
        return CommonResult.success();
    }

    /**
     * 更新用户角色
     * @param name 用户名
     * @param roleId 角色id
     */
    @PostMapping("/role")
    @Operation(summary = "更新用户角色", security = @SecurityRequirement(name = "Authorization"))
    public CommonResult<Void> updatePermission(
            @RequestParam("name") @NotBlank String name
            , @RequestParam("roleId") @NotNull Integer roleId) {
        userService.updateUserRole(name,roleId);
        return CommonResult.success();
    }


}
